<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../vue.js"></script>
</head>

<body>

  <div id="app">
    <input type="text" ref="username" /><button @click="submit">提交</button>
    <custom-layout ref="abc"></custom-layout>
  </div>



  <script>

    Vue.component('custom-layout', {
      template: `<h1><comp-a></comp-a></h1>`,
      data(){
        return {
          name:"admin"
        }
      },
      mounted() {
        console.log(this.$root.msg)
        this.$root.test()
      },
      components:{
        'comp-a':{
          template:'<span>comp-a</span>',
          mounted(){
         console.log(this.$parent.name);
          }
        }
      }
    })

    var vm = new Vue({
      el: "#app",
      data: {
        msg: "b"
      },
      mounted() {
        // this.msg;
        // console.log(this.$root.msg)
      //  console.log(this.$refs.username);
      },
      methods:{
        submit(){
          console.log(this.$refs.username.value);
          console.log('root:',this.$refs.abc.name)
        },
        test(){
          console.log('from root test function')
        }
      }
    })

  </script>
</body>

</html>